<!--重新保存项目-->
<template>
  <div class="resave-project-box">
    <el-form
        label-position="left"
        label-width="1.5rem"
        :model="Form"
        ref="tcItem"
    >
      <el-row>
        <h2 class="ne-title-v2">项目信息</h2>
        <tc-form2 :rules="rules" ref="tcForm2" :form="Form">
        </tc-form2>
      </el-row>
      <el-row>
        <el-col :span="24" class="text-center">
          <el-button type="primary" size="medium" @click="validate(false)" v-loading.fullscreen.lock="loading">保存</el-button>
          <el-button size="medium" @click="validate(true)" v-loading.fullscreen.lock="loading">保存送审核</el-button>
        </el-col>
      </el-row>
    </el-form>
    <el-dialog append-to-body title="送审" v-if="dialogVisible" :visible.sync="dialogVisible">
      <SendAudit :show.sync="dialogVisible"
                 :ODKInfo="ODKInfo"
                 :CTOInfo="CTOInfo"
                  v-bind="$attrs"
                  v-on="$listeners"
      ></SendAudit>
    </el-dialog>
  </div>
</template>
<script>
import TcForm2 from "@/components/public/TcForm2";
import SendAudit from "@/components/custorder/pengding/SendAudit";
import OrderService from "@/api/order/OrderService.js";
import { mapState } from "vuex";
export default {
  name: "ResaveProject",
  data() {
    return {
      dialogVisible: false,
      loading:false,
      ODKInfo: {},
      CTOInfo: {},
      Form: {
        oldPartyCode:'',
        "marketProjectId": {
          type: '',
          name: '',
          value: '',
          show: false,
          span: 6
        },
        "subProjectId": {
          type: '',
          name: '',
          value: '',
          show: false,
          span: 6
        },
        "custSoNumber": {
          type: 'Ipt',
          name: '流水号',
          value: '',
          // readonly: true,
          show: true,
          span: 6
        },
        "orderSourceId": {
          name: '受理运营商',
          type: 'select',
          value: '',
          options: [],
          required: true,
          filterable: true,
          show: true,
          span: 6,
        },
        "custName": {
          type: 'seeIpt',
          name: '客户名称',
          value: '',
          // readonly: true,
          show: true,
          span: 6
        },
        "contactName": {
          type: 'Ipt',
          name: '客户联系人',
          value: '',
          // readonly: true,
          required: true,
          show: true,
          span: 6
        },
        "contactOfficePhone": {
          type: 'Ipt',
          name: '客户联系人电话',
          value: "",
          // readonly: true,
          required: true,
          show: true,
          span: 6
        },
        "custAddr": {
          type: 'seeIpt',
          name: '客户地址',
          value: "",
          // readonly: true,
          required: true,
          show: true,
          span: 6
        },
        "custManagerId": {
          name: '客户经理',
          type: 'custDig',
          value: "",
          sname: '',
          rowMsg:'',
          required: true,
          show: true,
          span: 6,
        },
        "busiManagerId": {
          name: '项目经理',
          type: 'busiDig',
          value: "",
          sname: '',
          rowMsg:'',
          required: true,
          show: true,
          span: 6,
        },
        "saleCd": {
          name: '商机',
          type: 'saleDig',
          value: "",
          sname: "",
          rowMsg:'',
          required: true,
          show: true,
          span: 6,
        },
        "contactCd": {
          name: '合同编码',
          type: 'contactCdDig',
          value: "",
          sname: "",
          rowMsg:'',
          required: true,
          show: true,
          span: 6,
        },
        "contractName": {
          type: 'Ipt',
          name: '合同名称',
          value: "",
          disabled:true,
          show: true,
          span: 6
        },
        "projectId": {
          name: 'MSS项目编码',
          type: 'projectDig',
          value: "",
          sname: "",
          rowMsg:'',
          show: true,
          span: 6,
        },
        "marketProjectCode": {
          name: '营销项目编码',
          type: 'marketProject',
          value: "",
          show: true,
          span: 6,
        },
        "marketProjectName": {
          type: 'Ipt',
          name: '营销项目名称',
          value: "",
          disabled:true,
          show: true,
          span: 6
        },
        "marketSubprojectCode": {
          name: '营销子项目编码',
          type: 'marketSubProject',
          value: "",
          rowMsg:'',
          show: true,
          span: 6,
        },
        "marketSubprojectName": {
          type: 'Ipt',
          name: '营销子项目名称',
          value: "",
          disabled:true,
          show: true,
          span: 6
        },
        "oneSubFlag": {
          name: '是否跨域业务',
          type: 'radioIpt',
          value: "",
          options: [{label: '否', value: '0'},
            {label: '是', value: '1'},],
          show: true,
          span: 6,
        },
        // "contactNumberType": {
        //   name: '合同编号类型',
        //   type: 'select',
        //   value: "",
        //   options: [{label: '实线接入', value: 'MSS合同编号'}],
        //   required: false,
        //   show: false,
        //   span: 6,
        // },
        // "contactEmail": {
        //   type: 'Ipt',
        //   name: '客户Email',
        //   value: "",
        //   readonly: true,
        //   show: false,
        //   span: 6
        // },
        // "contactFax": {
        //   type: 'Ipt',
        //   name: '客户传真',
        //   value: "",
        //   readonly: true,
        //   show: false,
        //   span: 6
        // },
        // "isCountyFlag": {
        //   name: '是否为区县一站服务需求',
        //   type: 'select',
        //   value: "",
        //   options: [{label: '否', value: '0'},
        //     {label: '是', value: '1'},],
        //   required: false,
        //   show: false,
        //   span: 6,
        // },
        // "projectName": {
        //   type: 'Ipt',
        //   name: '项目名称',
        //   value: "",
        //   readonly: true,
        //   show: false,
        //   span: 6
        // },
        // "bussDesc": {
        //   type: 'Ipt',
        //   name: '项目描述',
        //   value: "",
        //   readonly: true,
        //   show: false,
        //   span: 6
        // },
        // "projectManagerName": {
        //   name: '项目经理',
        //   type: 'IptDig2',
        //   value: "",
        //   required: true,
        //   show: true,
        //   span: 6,
        // },
        // "custWorkName": {
        //   name: '集团客工',
        //   type: 'IptDig2',
        //   value: "",
        //   required: false,
        //   show: false,
        //   span: 6,
        // },
        // "custWorkIphone": {
        //   type: 'Ipt',
        //   name: '集团客工联系电话',
        //   value: "",
        //   readonly: true,
        //   show: false,
        //   span: 6
        // },
        // "custWorkEmail": {
        //   type: 'Ipt',
        //   name: '集团客工邮箱',
        //   value: "",
        //   readonly: true,
        //   show: false,
        //   span: 6,
        //   marginRight: '25%'
        // },
        // "temp2": {
        //   type: 'select',
        //   name: '拓扑层级',
        //   value: "",
        //   options: [],
        //   readonly: true,
        //   required: false,
        //   show: false,
        //   span: 6,
        //   marginRight: '75%'
        // },
        // "temp1": {
        //   type: 'select',
        //   name: '是否捆绑网管专家',
        //   value: "",
        //   options: [{label: '否', value: '0'},
        //     {label: '是', value: '1'}],
        //   readonly: true,
        //   required: false,
        //   show: false,
        //   span: 6,
        //   marginRight: '75%'
        // },
        // "remark": {
        //   type: 'textarea',
        //   name: '备注',
        //   value: "",
        //   readonly: true,
        //   show: false,
        //   span: 12
        // }
      },
      rules: {
        // contactCd: [
        //   { required: true, message: "合同编码不能为空", trigger: "change" },
        //   { required: true, message: "合同编码不能为空", trigger: "blur" },
        // ],
        orderSourceId: [
          { required: true, message: "受理运营商不能为空", trigger: "change" },
        ],
        custName: [
          { required: true, message: "客户名称不能为空", trigger: "change" },
        ],
        contactName: [
          { required: true, message: "客户联系人不能为空", trigger: "blur" },
          { required: true, message: "客户联系人不能为空", trigger: "change" },
        ],
        contactOfficePhone: [
          { required: true, message: "客户联系电话不能为空", trigger: "blur" },
          { required: true, message: "客户联系电话不能为空", trigger: "change" },
        ],
        custAddr: [
          { required: true, message: "客户地址不能为空", trigger: "change" },
          { required: true, message: "客户地址不能为空", trigger: "blur" },
        ],
        custManagerId: [
          { required: true, message: "客户经理不能为空", trigger: "change" },
          { required: true, message: "客户经理不能为空", trigger: "blur" },
        ],
        busiManagerId: [
          { required: true, message: "项目经理不能为空", trigger: "change" },
          { required: true, message: "项目经理不能为空", trigger: "blur" },
        ]
      },
    }
  },
  props: {
    ProInfo: {
      type: [Object, Array]
    }
  },
  mounted() {

  },
  created() {
    this.getProjectInfo();
    //受理运营商
    let params = { attrId: "100010765", productId: "" };
    this.getAttrValueList(params);
  },
  computed:{
    ...mapState('orders',['orderPosInfo']),
    ...mapState('user',['user'])
  },
  watch:{
    'Form.contactCd.sname': {
      handler(newValue, oldValue) {
        this.Form.contractName.value = newValue;
      }
    }
  },
  components: {
    TcForm2,
    SendAudit
  },
  methods: {
    validate(vis){
      
      this.$refs['tcItem'].validate((valid) => {
        
        if (valid) {
          this.saveProject(vis);
        } else {
          
          return false;
        }
      });
    },
    //受理运营商
    async getAttrValueList(params) {
      //获取页面下拉框值
      const result = await OrderService.getAttrValueList(params);
      if (result.code == 200) {
        let attrValueList = result.meta.attrValueList;
        let opt = [];
        attrValueList.forEach((item,index)=>{
          opt.push({label:item.attrValueName,value:item.attrValue+''});
        });
        
        this.Form.orderSourceId.options = [...opt];
        
      }
    },
    async getProjectInfo(){
      // 填充页面回显数据
      this.Form.custSoNumber.value = this.ProInfo.custSoNumber;
      this.Form.orderSourceId.value = this.ProInfo.orderSourceId;
      this.Form.custName.value = this.orderPosInfo.custMsg.custName?this.orderPosInfo.custMsg.custName:'';
      this.Form.oldPartyCode = this.orderPosInfo.custMsg.oldPartyCode ? this.orderPosInfo.custMsg.oldPartyCode:'';
      this.Form.contactName.value = this.orderPosInfo.custMsg.contactName?this.orderPosInfo.custMsg.contactName:'';
      this.Form.contactOfficePhone.value = this.orderPosInfo.custMsg.contactMobilePhone?this.orderPosInfo.custMsg.contactMobilePhone:'';
      this.Form.custAddr.value = this.orderPosInfo.custMsg.custAddr?this.orderPosInfo.custMsg.custAddr:'';
      // this.Form.contactFax.value = this.orderPosInfo.custMsg.contactFax?this.orderPosInfo.custMsg.contactFax:'';
      let {modType,custSoNumber,custOrderType} = this.ProInfo,
          custId = this.orderPosInfo.custId;
      const result = await OrderService.qryModProjectInfo({modType,custSoNumber,custId,modType:custOrderType});
      if(result.meta.resCode=='0'){
        let cres = result.meta.resList.executeSqlResps[0];
        if(!cres) return
        for(var key in cres){
          if(this.Form.hasOwnProperty(key)){
            this.Form[key].value=cres[key];
          }
        }
        this.Form.busiManagerId.sname = cres.busiManagerName ? cres.busiManagerName : '';
        this.Form.custManagerId.sname = cres.custManagerName ? cres.custManagerName : '';
        this.Form.marketProjectId = cres.marketProjectId ? cres.marketProjectId : '';
        this.Form.subProjectId = cres.subProjectId ? cres.subProjectId : '';
        if(this.Form.marketProjectId){
          this.$refs.tcForm2.infoTip = false;
        }
      }else{
        this.$message({
          showClose: true,
          message: result.meta.resMsg,
          type: 'error'
        });
      }
    },
    async saveProject(vis){
      let {custOrderId,custSoNumber,custOrderType} = this.ProInfo;
      let params = {
        operType : '1000',
        createStaff: this.user.staffId,
        createOrgId: this.user.orgId,
        orgId:this.user.orgId,
        accepteRegionId: this.user.regionId,
        accepteLanId: this.user.regionId,
        channelId: '10',
        extCustOrderId: '',
        custId: this.orderPosInfo.custId,
        sysSource: '1000',
        orderSource: '1000',
        saleId: this.orderPosInfo.custMsg.saleId?this.orderPosInfo.custMsg.saleId:'',
        // bussDesc : this.Form.bussDesc.value,
        // remark: this.Form.remark.value,
        contactId:'',
        contactCd: this.Form.contactCd.value,
        projectId: this.Form.projectId.value,
        // projectName: '',
        projectManage: '',
        saleId: '',
        custManagerId: this.Form.custManagerId.value,
        busiManagerId: this.Form.busiManagerId.value,
        contactName: this.Form.contractName.value,
        // contactNumberType: this.Form.contactNumberType.value,
        // isCountyFlag: this.Form.isCountyFlag.value,
        marketProjectCode:this.Form.marketProjectCode.value,//营销项目编码
        marketProjectName:this.Form.marketProjectName.value,//营销项目名称
        marketProjectId:this.Form.marketProjectId,//营销项目Id
        marketSubprojectCode:this.Form.marketSubprojectCode.value,//营销子项目编码
        marketSubprojectName:this.Form.marketSubprojectName.value,//营销子项目名称
        subProjectId:this.Form.subProjectId,//营销子项目id
        oneSubFlag: this.Form.oneSubFlag.value,
        orderContactInfo: [{
          contactType: '1',
          contactName: this.Form.contactName.value,
          homePhone: '',
          officePhone: this.Form.contactOfficePhone.value,
          // contactEmail: this.Form.contactEmail.value,
          // fax: this.Form.contactFax.value,
          locationId: this.orderPosInfo.custMsg.locationId?this.orderPosInfo.custMsg.locationId:'',
          contactAddress: this.Form.custAddr.value
        }]
      };
      this.loading = true;
      const result = await OrderService.createProject({custOrderId,custSoNumber,custOrderType,...params});
      this.loading = false;
      if(result.meta.resultCode == '0'){
        this.$message({
          type: 'success',
          message: '保存成功!'
        });
        if(vis){
          let {activityId,batchNbr,custId,custOrderId,custSoNumber,orderAuditIds,orderAuditId,processInstId,tacheId,taskId} = result.meta.resultObject.customerOrder;
          this.ODKInfo = {orderAuditId, taskId, tacheId , activityId, processInstId,orderAuditIds,orderAuditId,ifTmp:true};
          this.CTOInfo = {batchNbr,custId,custOrderId,custSoNumber,orderAuditIds,orderAuditId};
          this.dialogVisible = true;
        }else{
          this.$emit('update:show',false);
          this.$parent.$parent.getTempList();
        }
      }else{
        this.$message({
          showClose: true,
          message: result.meta.resultMsg,
          type: 'error'
        });
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.resave-project-box {

}
</style>
